# @Time    :2025/4/8 15:47
import requests

# 一言网的 API 地址  (海外)
url = 'https://international.v1.hitokoto.cn'
params = {
    "c": "a",  # a,代表动画，b代表漫画
    "encode": "json"
}
try:
    print(f"正在发送 GET 请求到: {url}，参数: {params}")
    # 获取请求的响应对象
    response = requests.get(url, params=params)
    # 获取状态码
    status_code = response.status_code
    if status_code == 200:
        print(f"请求成功，状态码是{status_code}")
        data = response.json()
        hitokoto = data['hitokoto']
        from_who = data['from_who' if data['from_who'] else '未知']
        print(f"随机名言：{hitokoto} -{from_who}写的")
    elif status_code == 404:
        print(f"请求的资源未找到！状态码: {status_code}")
    elif status_code == 500:
        print(f"服务器内部错误！状态码: {status_code}")
    else:
        print(f"发生未知错误，状态码: {status_code}")
except requests.RequestException as e:
    print(f"请求过程中出现错误: {e}")

"""
核心代码：

import requests

# 一言网的 API 地址  (海外)
url = 'https://international.v1.hitokoto.cn'
params = {
    "c": "a", #a,代表动画，b代表漫画
    "encode": "json"
}

# 获取请求的响应对象
response = requests.get(url, params=params)
# 获取状态码
status_code=response.status_code
data=response.json()
hitokoto=data['hitokoto']
from_who=data['from_who' if data['from_who'] else '未知']
print(f"随机名言：{hitokoto} -{from_who}写的")

"""
